﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using BLL.Entities.Company;
using BLL.Entities;

namespace HTAProDataImporter.Transport
{
    public class PoliceOfficerTransport : BaseEntityTransport
    {
        public override string CommandText
        {
            get { return "select * from tblOfficer"; }
        }

        public override void InstanceFromReader(OleDbDataReader DR)
        {
            PoliceOfficer officer = Judge.CreateNewInstance<PoliceOfficer>();

            officer.Person.FirstName = DR["FirstName"].ToString();
            officer.Person.LastName = DR["LastName"].ToString();
            officer.Notes = DR["comments"].ToString();


            if (!string.IsNullOrEmpty(DR["iconnumber"].ToString()))
                try
                {
                    officer.ICON = DataStore.ICON[DR["iconnumber"].ToString()];
                }
                catch (Exception ex)
                {
                    Warnings.Add(string.Format("Can't find Officer ICON for key IconID {0}, OfficerID {1}", DR["iconnumber"], DR["pkOfficerID"]));
                }
            else
                Warnings.Add(string.Format("Officer has no ICON OfficerID {0}", DR["pkOfficerID"]));
                

            officer.Badge = DR["BadgeNumber"].ToString();
            officer.Division = DR["DivisionNumber"].ToString();
            officer.IsRetired = Convert.ToBoolean(DR["ynRetired"]);

            DataStore.PoliceOfficers.Add(DR["pkOfficerID"].ToString(), officer);


        }
    }
}
